package com.sright.bcard.enterprise.biz.manager.impl;

import com.sright.bcard.common.service.share.enums.IndustryTypeEnum;
import com.sright.bcard.common.service.share.utils.DataConvertUtils;
import com.sright.bcard.enterprise.biz.manager.IndustryManager;
import com.sright.bcard.enterprise.dal.dao.IndustryDAO;
import com.sright.bcard.enterprise.dal.entity.IndustryDO;
import com.sright.bcard.common.service.share.dto.enterprise.IndustryDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
@Slf4j
public class IndustryManagerImpl implements IndustryManager {

    @Autowired
    private IndustryDAO industryDAO;

    @Override
    public List<IndustryDTO> industryList() {
        log.info("开始查询全量行业列表");
        List<IndustryDO> industryDOList = industryDAO.selectAll();
        if(CollectionUtils.isNotEmpty(industryDOList)) {
            // DO 转化 DTO
            List<IndustryDTO> industryDTOList = new ArrayList<>();
            DataConvertUtils.convertDOList2DTOList(industryDOList, industryDTOList, IndustryDTO.class);
            return industryDTOList;
        }
        return new ArrayList<>();
    }

    @Override
    public List<IndustryDO> personalIndustryList() {
        return industryDAO.selectByType(IndustryTypeEnum.PERSONAL.getValue());
    }
}
